package q633_judgeSquareSum;

public class Solution {
    /*
    简单双指针，只需创建左右两个指针不停缩小范围即可
    注意左右指针要用long类型
     */
    public boolean judgeSquareSum(int c) {
        long l = 0, r = (int) Math.sqrt(c) + 1;
        while (l <= r) {
            if (l * l + r * r < c) {
                l++;
            }else if (l * l + r * r > c) {
                r--;
            }else {
                return true;
            }
        }
        return false;
    }
}
